﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using MossmanMill.View;

namespace MossmanMill
{
    public class Processor : Slottable
    {
        public int ProcessorId { get; private set; } //Processor_Id
        public string Model { get; private set; } //Processor_Model

        public Processor(int id, int rackId, string model, int position, int slotId = -1)
        {
            SlotType = 'P';
            ProcessorId = id;
            RackId = rackId;
            Model = model;
            SlotId = slotId;
            Position = position;
        }

        public override string ToString()
        {
            return Model;
        }

        public override string[] GetInfo()
        {
            string[] str = new string[2];
            str[0] = "Processor";
            str[1] = Model;
            return str;
        }

        public override Bitmap GetDrawBitmap(Rectangle bounds, DrawType type)
        {
            var x = bounds.Left;
            var y = bounds.Top;
            var buffer = new Bitmap(bounds.Width, bounds.Height);
            var g = Graphics.FromImage(buffer);
            if (type == DrawType.Icon)
            {
                Drawing.FillOutlineRectangle(g, new Rectangle(0, 0, 32, 32), Brushes.PowderBlue, Pens.Black);
                g.DrawString(Model.Substring(0, Model.Length / 2), Fonts.smallTimes, Brushes.Black, 0, 0);
                g.DrawString(Model.Substring(Model.Length / 2), Fonts.smallTimes, Brushes.Black, 0, 16);
                return buffer;
            }
            Drawing.FillOutlineRectangle(g, new Rectangle(0, 0, 160, 160), Brushes.PowderBlue, Pens.Black);
            g.DrawString("Processor", Fonts.largeTimes, Brushes.Black, 10, 0);
            g.DrawString(Model, Fonts.largerCourier, Brushes.Black, 10, 40);
            Drawing.DrawCircuit(g, 94, 94);
            return buffer;
        }

        public override void draw(System.Drawing.Graphics graphics, int x, int y, float scale = 1.0f, bool drawChildren = false)
        {
            draw(graphics, new Rectangle(x, y, 161, 161), scale, drawChildren);
        }

        public override void draw(Graphics graphics, Rectangle bounds, float scale = 1.0f, bool drawChildren = false)
        {
            var x = bounds.Left;
            var y = bounds.Top;
            var buffer = GetDrawBitmap(bounds, DrawType.Full);           
            graphics.DrawImage(buffer, x, y, buffer.Width * scale, buffer.Height * scale);

        }

        public override bool interact(System.Drawing.Point location, int type, int x, int y, float scale = 1.0f, bool interactWithChildren = false)
        {
            return false;
        }

        public bool Equals(Processor pCard)
        {
            return base.Equals(pCard) &&
                pCard.Model.Equals(Model);
        }

        public Processor Copy()
        {
            return new Processor(ProcessorId, RackId, Model, Position, SlotId);
        }
    }
}
